<?
function hapus(){
	global $inp,$inp_par;

	$sql_="delete from tbl_spt where no_faktur_pajak='$inp_par[no_faktur_pajak]' and id_leveransir='$inp_par[id_leveransir]' and divisi_kode='$inp_par[divisi_kode]'";
	dbresult($sql_);
echo $sql_;
	echo "<script>window.location='?".var_kirim($inp_par,"mode")."';</script>";
}


function ubah(){
	global $inp,$inp_par,$cnama;
        $inp[no_faktur_pajak] = $inp[nofak1].".".$inp[nofak2]."-".$inp[nofak3].".".$inp[nofak4];
        $tgl_faktur = $inp[tahun]."-".$inp[bulan]."-".$inp[hari];
        $inp[dpp] = str_replace(",","",$inp[dpp]);
        $inp[ppn] = str_replace(",","",$inp[ppn]);
        if ($inp[is_buku]==""){
            $inp[is_buku]='N';
            $inp[bukti_pembukuan] = "";
        }else{
            $inp[is_buku]='Y';
        }
        if ($inp[is_bayar]==""){
            $inp[is_bayar]='N';
            $inp[bukti_pembayaran] = "";
        }else{
            $inp[is_bayar]='Y';
        }
        if ($inp[is_lapor]==""){
            $inp[is_lapor]='N';
            $tgl_lapor = "-";
        }else{
            $inp[is_lapor]='Y';
            if (strlen($inp[bulan4])==1){
                $inp[bulan4] = "0".$inp[bulan4];
            }
            $tgl_lapor = $inp[tahun4]."-".$inp[bulan4];
        }

        $sql="UPDATE tbl_spt SET no_faktur_pajak='".trim($inp[no_faktur_pajak])."',
                                    id_proyek='".trim($inp[id_proyek])."',
                                    id_leveransir='".trim($inp[id_leveransir])."',
                                    tgl_faktur='".$tgl_faktur."',
                                    dpp='".trim($inp[dpp])."',
                                    ppn='".trim($inp[ppn])."',
                                    update_date='".e_getDateNow()."',
                                    update_by='".$cnama."',
                                    update_ip='".e_getIpAddr()."',
                                    is_buku='".$inp[is_buku]."',
                                    is_bayar='".$inp[is_bayar]."',
                                    bukti_pembukuan='".trim($inp[bukti_pembukuan])."',
                                    bukti_pembayaran='".trim($inp[bukti_pembayaran])."',
                                    is_lapor='".$inp[is_lapor]."',
                                    tanggal_lapor='".$tgl_lapor."'
                                    WHERE no_faktur_pajak='".$inp_par[no_faktur_pajak]."' AND id_leveransir='".$inp_par[id_leveransir]."' and divisi_kode='$inp_par[divisi_kode]'";
        
        if ($inp_par[no_faktur_pajak]==$inp[no_faktur_pajak]){
                dbresult($sql);
                echo "<script>window.location='?".var_kirim($inp_par,"mode")."';</script>";
        }else{
            $sql_cek = "select no_faktur_pajak from tbl_spt where no_faktur_pajak = '".trim($inp[no_faktur_pajak])."' and id_leveransir='".trim($inp[id_leveransir])."' limit(1)";
            $res_cek = dbresult($sql_cek);
            $r_cek = pg_num_rows($res_cek);
            if((int)$r_cek < 1){
                dbresult($sql);
                echo "<script>window.location='?".var_kirim($inp_par,"mode")."';</script>";
            }else{
                echo "<script>alert('NO Faktur sudah ada Di Database.. !!')</script>";
                echo "<script>window.history.back();</script>";
            }
        }
}


function tambah(){
	global $inp,$inp_par,$cnama,$cdivisi_kode;
	$nofak = $inp[nofak1].".".$inp[nofak2]."-".$inp[nofak3].".".$inp[nofak4];
        $tgl_faktur = $inp[tahun]."-".$inp[bulan]."-".$inp[hari];
        $inp[dpp] = str_replace(",","",$inp[dpp]);
        $inp[ppn] = str_replace(",","",$inp[ppn]);
        if ($inp[is_buku]==""){
            $inp[is_buku]='N';
            $inp[bukti_pembukuan] = "";
        }else{
            $inp[is_buku]='Y';
        }
        if ($inp[is_bayar]==""){
            $inp[is_bayar]='N';
            $inp[bukti_pembayaran] = "";
        }else{
            $inp[is_bayar]='Y';
        }
        if ($inp[is_lapor]==""){
            $inp[is_lapor]='N';
            $tgl_lapor = "-";
        }else{
            $inp[is_lapor]='Y';
            if (strlen($inp[bulan4])==1){
                $inp[bulan4] = "0".$inp[bulan4];
            }
            $tgl_lapor = $inp[tahun4]."-".$inp[bulan4];
        }
        $sql_cek = "select no_faktur_pajak from tbl_spt where no_faktur_pajak = '".trim($nofak)."' and id_leveransir='".trim($inp[id_leveransir])."' limit(1)";
	$res_cek = dbresult($sql_cek);
	$r_cek = pg_num_rows($res_cek);
        if((int)$r_cek < 1){
            $sql="INSERT INTO tbl_spt (no_faktur_pajak,id_leveransir,tgl_faktur,dpp,ppn,
            bukti_pencatatan,id_proyek,entry_date,entry_by,update_date,update_by,entry_ip,update_ip,is_buku,is_bayar,bukti_pembukuan,bukti_pembayaran,divisi_kode,is_lapor,tanggal_lapor)
            VALUES ('".trim($nofak)."','".trim($inp[id_leveransir])."','".$tgl_faktur."','".trim($inp[dpp])."','".trim($inp[ppn])."',
                   '','".trim($inp[id_proyek])."','".e_getDateNow()."','".$cnama."','".e_getDateNow()."','".$cnama."','".e_getIpAddr()."',
                   '".e_getIpAddr()."','".$inp[is_buku]."','".$inp[is_bayar]."','".trim($inp[bukti_pembukuan])."','".trim($inp[bukti_pembayaran])."','".$cdivisi_kode."','".$inp[is_lapor]."','".$tgl_lapor."')";
    //echo $sql."<br>";
            dbresult($sql);
            echo "<script>window.location='?".var_kirim($inp_par,"mode")."';</script>";
        }else{
            echo "<script>alert('NO Faktur sudah ada Di Database.. !!')</script>";
            echo "<script>window.history.back();</script>";
        }

	

}

function form(){
	global $inp_par,$inp,$cdivisi_kode;
	if($inp_par[mode]=="edit"){
		$sql="select * from tbl_spt where no_faktur_pajak='$inp_par[no_faktur_pajak]' and id_leveransir='$inp_par[id_leveransir]' and divisi_kode='$inp_par[divisi_kode]'";
		$res=dbresult($sql);
		$r=pg_fetch_array($res);
//                $checkF = "readOnly";
	}

	$r[no_faktur_pajak1]=$inp[no_faktur_pajak]==""?$r[no_faktur_pajak]:$inp[no_faktur_pajak];
        $r[no_faktur_pajak] = str_replace(".","-",$r[no_faktur_pajak1]);
        $arrF=split("-",$r[no_faktur_pajak]);

        $arrF[2] = $arrF[2] == ""? substr(date("Y"),2,2):$arrF[2];

        $r[tgl_faktur]=$inp[tgl_faktur]==""?$r[tgl_faktur]:$inp[tgl_faktur];
        $arr=split("-",$r[tgl_faktur]);
	$hari=$arr[2]==""?date('j'):$arr[2];
	$bulan=$arr[1]==""?date('n'):$arr[1];
	$tahun=$arr[0]==""?date('Y'):$arr[0];

        $r[id_leveransir] = $inp[id_leveransir]==""?$r[id_leveransir]:$inp[id_leveransir];

        $r[dpp] = $inp[dpp]==""?$r[dpp]:$inp[dpp];
        $r[ppn] = $inp[ppn]==""?$r[ppn]:$inp[ppn];
        $r[id_proyek] = $inp[id_proyek]==""?$r[id_proyek]:$inp[id_proyek];

        $r[is_buku] = $inp[is_buku] ==""?$r[is_buku]:$inp[is_buku];
        $r[is_buku] = ($r[is_buku]=="true" or $r[is_buku]=="Y") ?"checked":"";
        $buku = $r[is_buku]==""?"disabled":"";
        $r[bukti_pembukuan] = $inp[bukti_pembukuan]==""?$r[bukti_pembukuan]:$inp[bukti_pembukuan];
        $r[bukti_pembukuan] = $r[is_buku]==""?"":$r[bukti_pembukuan];

        $r[is_bayar] = $inp[is_bayar] ==""?$r[is_bayar]:$inp[is_bayar];
        $r[is_bayar] = ($r[is_bayar]=="true" or $r[is_bayar]=="Y")?"checked":"";
        $bayar = $r[is_bayar]==""?"disabled":"";
        $r[bukti_pembayaran] = $inp[bukti_pembayaran]==""?$r[bukti_pembayaran]:$inp[bukti_pembayaran];
        $r[bukti_pembayaran] = $r[is_bayar]==""?"":$r[bukti_pembayaran];

        $r[is_lapor] = $inp[is_lapor] ==""?$r[is_lapor]:$inp[is_lapor];
        $r[is_lapor] = ($r[is_lapor]=="true" or $r[is_lapor]=="Y")?"checked":"";
        $lapor = $r[is_lapor]==""?"t":"";

        $r[tanggal_lapor] = $inp[tanggal_lapor]==""?$r[tanggal_lapor]:$inp[tanggal_lapor];
        $arr3 = split("-",$r[tanggal_lapor]);
        $bulan4 = $arr3[1]==""?date('n'):$arr3[1];
        $tahun4 = $arr3[0]==""?date('Y'):$arr3[0];



        generate_rule("is_isi","inp[nofak1]","Anda Harus Mengisi No. FAKTUR");
        generate_rule("is_rangesd","inp[nofak1]","No. FAKTUR Tidak Lengkap","0","3");
        generate_rule("is_rangesd","inp[nofak2]","No. FAKTUR Tidak Lengkap","0","3");
        generate_rule("is_rangesd","inp[nofak4]","No. FAKTUR Tidak Lengkap","0","8");
                    
	generate_rule("is_isi","inp[nama_leveransir]","Anda Harus Mengisi Nama Leveransir");
	generate_rule("is_isi","inp[dpp]","Anda Harus Mengisi DPP");
	generate_rule("is_isi","inp[nama_proyek]","Anda Harus Mengisi Nama Proyek");
        if ($r[is_buku]!=""){
            generate_rule("is_isi","inp[bukti_pembukuan]","Anda Harus Mengisi Bukti Pembukuan");
        }
        if ($r[is_bayar]!=""){
            generate_rule("is_isi","inp[bukti_pembayaran]","Anda Harus Mengisi Bukti Pembayaran");
        }

	$txtout=generate_validasi();


	$txtout.="<table width=\"98%\" height=\"35\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr> 
		<td height=\"5\" colspan=\"2\"><img src=\"../img/0.gif\" width=\"1\" height=\"10\"></td>
		</tr>
		<tr> 
		<td width=\"15\" background=\"../img/bg-jdl-ppn.gif\">&nbsp;</td>
		<td height=\"25\" background=\"../img/bg-jdl-ppn.gif\"><img src=\"../img/jdl-faktur-pajak-masukan.gif\" height=\"25\"></td>
		</tr>
		</table>
		<form name=form1 method=post action=\"?".var_kirim($inp_par)."\" onsubmit=\"return validasi(document.form1);\">
		<table width=\"700\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"C6E6FF\" class=\"tabel1\">
		<tr class=\"tbltagihan\"> 
		<td colspan=\"3\">Form Input Faktur Pajak</td>
		</tr>

		<tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">1.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">NO FAKTUR</td>
		<td><input name=\"inp[nofak1]\" type=\"text\" class=\"form2\" value=\"$arrF[0]\" size=\"3\" maxlength=\"3\" onkeyup=\"nextField('inp[nofak1]','inp[nofak2]');\" $checkF>.<input name=\"inp[nofak2]\" type=\"text\" class=\"form2\" value=\"$arrF[1]\" size=\"3\" maxlength=\"3\" onkeyup=\"nextField('inp[nofak2]','inp[nofak3]');\" $checkF>-".combo_tanggal("inp[nofak3]",$arrF[2],$arrF[2]-7,$arrF[2]+7,"","$checkFC","onChange=gantitahun();").".<input name=\"inp[nofak4]\" type=\"text\" class=\"form2\" value=\"$arrF[3]\" size=\"8\" maxlength=\"8\" $checkF></td>
		</tr>

		<tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"> <div align=\"center\">2.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">TANGGAL FAKTUR</td>
		<td bgcolor=\"#FFFFFF\"> ".combo_tanggal("inp[hari]",$hari,1,31)." ".combo_bulan("inp[bulan]",$bulan)." <input name=\"inp[tahun]\" type=\"text\" class=\"form2\" size=\"4\" value=".trim($tahun)." readonly></td>
		</tr>

		<tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"> <div align=\"center\">3.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">NAMA REKANAN</td>
		<td><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"tabel1\">
		<tr>
		<td><textarea name=\"inp[nama_leveransir]\" class=\"form2\" rows=2 cols=40 readOnly>".(trim($r["id_leveransir"]) <> ""?"".trim(cari_nilai("select nama_leveransir from m_leveransir where id_leveransir='".trim($r["id_leveransir"])."' "))."":"")."</textarea></td>
		<td bgcolor=#FFFFFF>&nbsp; <input type=\"button\" name=\"Submit222222\" value=\"Rekanan\" class=\"tombolgo\" onclick=window.location=\"javascript:Customer()\">
		<input name=\"inp[id_leveransir]\" type=\"hidden\" class=\"form2\" size=\"30\" value=".trim($r[id_leveransir])." ></td>
		</tr>
		</table></td>
		</tr>

		<tr bgcolor=\"#FFFFFF\"> 
		<td width=\"30\" valign=\"top\"> <div align=\"center\">4.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">NPWP REKANAN</td>
		<td bgcolor=\"#FFFFFF\" valign=\"top\"><input name=\"inp[npwp_leveransir]\" type=\"text\" class=\"form2\" size=\"30\" value=\"".(trim($r["id_leveransir"]) <> ""?"".trim(cari_nilai("select npwp_leveransir from m_leveransir where id_leveransir='".trim($r["id_leveransir"])."' "))."":"")."\" ></td>
		</tr>

		<tr bgcolor=\"#FFFFFF\"> 
		<td width=\"30\" valign=\"top\"> <div align=\"center\">5.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">ALAMAT REKANAN</td>
		<td bgcolor=\"#FFFFFF\" valign=\"top\"><textarea name=\"inp[alamat_leveransir]\" class=\"form2\" rows=2 cols=40 readOnly>".(trim($r["id_leveransir"]) <> ""?"".trim(cari_nilai("select alamat_leveransir from m_leveransir where id_leveransir='".trim($r["id_leveransir"])."' "))."":"")."</textarea></td>
		</tr>

		<tr bgcolor=\"#FFFFFF\">
		<td width=\"30\"> <div align=\"center\">6.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\">DPP</td>
		<td bgcolor=\"#FFFFFF\"><input onChange='itung()' onkeyup=\"angka(this);\" name=\"inp[dpp]\" type=\"text\" class=\"form2\" style=\"text-align: right\" size=\"20\" value='".trim(number_format($r[dpp]))."'></td>
		</tr>

		<tr bgcolor=\"#FFFFFF\"> 
		<td width=\"30\"> <div align=\"center\">7.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\">PPn</td>
		<td bgcolor=\"#FFFFFF\"> <input onblur=\"angka(this);\" name=\"inp[ppn]\" type=\"text\" class=\"form2\" style=\"text-align: right\" size=\"20\" value='".trim(number_format($r[ppn]))."' readOnly></td>
		</tr>

                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"> <div align=\"center\">8.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">NAMA PROYEK</td>
		<td><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"tabel1\">
		<tr>
		<td><textarea name=\"inp[nama_proyek]\" class=\"form2\" rows=2 cols=40 readOnly>".(trim($r["id_proyek"]) <> ""?"".trim(cari_nilai("select nama_proyek from m_proyek where id_proyek='".trim($r["id_proyek"])."' "))."":"")."</textarea></td>
		<td bgcolor=#FFFFFF>&nbsp; <input type=\"button\" name=\"Submit222222\" value=\"Proyek\" class=\"tombolgo\" onclick=window.location=\"javascript:Proyek()\">
		<input name=\"inp[id_proyek]\" type=\"hidden\" class=\"form2\" size=\"30\" value=".trim($r[id_proyek])." ></td>
		</tr>
		</table></td>
		</tr>

                <tr bgcolor=\"#FFFFFF\">
		<td width=\"30\"> <div align=\"center\">9.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\">PEMBUKUAN</td>
		<td bgcolor=\"#FFFFFF\"><input onClick=\"disable();\" type=\"checkbox\" name=\"inp[is_buku]\" value=\"Y\" $r[is_buku]></td>
		</tr>

                <tr bgcolor=\"#FFFFFF\">
		<td width=\"30\"> <div align=\"center\">10.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\">NO BUKTI PEMBUKUAN</td>
		<td bgcolor=\"#FFFFFF\"><input onkeyup=\"ToUpper(this)\" maxlength=\"13\" class=\"form2\" name=\"inp[bukti_pembukuan]\" $buku  value=".trim($r[bukti_pembukuan])."></td>
		</tr>

                <tr bgcolor=\"#FFFFFF\">
		<td width=\"30\"> <div align=\"center\">11.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\">PEMBAYARAN</td>
		<td bgcolor=\"#FFFFFF\"><input onClick=\"disable();\" type=\"checkbox\" name=inp[is_bayar] value=\"Y\" $r[is_bayar]></td>
		</tr>

                <tr bgcolor=\"#FFFFFF\">
		<td width=\"30\"> <div align=\"center\">12.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\">NO BUKTI PEMBAYARAN</td>
		<td bgcolor=\"#FFFFFF\"><input onkeyup=\"ToUpper(this)\" maxlength=\"13\" class=\"form2\" name=inp[bukti_pembayaran] $bayar value=".trim($r[bukti_pembayaran])."></td>
		</tr>

                <tr bgcolor=\"#FFFFFF\">
		<td width=\"30\"> <div align=\"center\">13.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\">LAPOR</td>
		<td bgcolor=\"#FFFFFF\"><input onClick=\"disable();\" type=\"checkbox\" name=inp[is_lapor] value=\"Y\" $r[is_lapor]></td>
		</tr>

                <tr bgcolor=\"#FFFFFF\">
		<td width=\"30\"> <div align=\"center\">14.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\">LAPOR SPT MASA</td>
		<td bgcolor=\"#FFFFFF\">".combo_bulan("inp[bulan4]",$bulan4,"",$lapor)."".combo_tanggal("inp[tahun4]",$tahun4,2000,2015,"",$lapor)."</td>
		</tr>
                ";

	$txtout.="<tr class=\"tbltagihan\">
		<td colspan=\"3\"><div align=\"center\"> 
		<input type=\"submit\" name=\"inp[aksi]\" value=\"Save &raquo;\" class=\"tombolgo\">
		<input type=\"button\" name=\"Submit2222222222\" value=\"Cancel &raquo;\" class=\"tombolgo\" onClick=\"window.location='?".var_kirim($inp_par,"mode,no_faktur_pajak")."'\">
		</div></td>
		</tr>
		</table>
		</form>
		";
	return $txtout;
}

function lihat(){
	global $inp_par,$inp,$permisi,$cdivisi_kode;
	$inp_par[hari]=$inp_par[hari]==""?1:$inp_par[hari];
	$inp_par[bulan]=$inp_par[bulan]==""?date('n'):$inp_par[bulan];
	$inp_par[tahun]=$inp_par[tahun]==""?date('Y'):$inp_par[tahun];
	$inp_par[hari_]=$inp_par[hari_]==""?date('j'):$inp_par[hari_];
	$inp_par[bulan_]=$inp_par[bulan_]==""?date('n'):$inp_par[bulan_];
	$inp_par[tahun_]=$inp_par[tahun_]==""?date('Y'):$inp_par[tahun_];
        $inp_par[divisi_kode]= $inp_par[divisi_kode] == ""? $cdivisi_kode:$inp_par[divisi_kode];

	$txtout.="<table width=\"98%\" height=\"35\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr> 
		<td height=\"5\" colspan=\"2\"><img src=\"../img/0.gif\" width=\"1\" height=\"10\"></td>
		</tr>
		<tr> 
		<td width=\"15\" background=\"../img/bg-jdl-ppn.gif\">&nbsp;</td>
		<td height=\"25\" background=\"../img/bg-jdl-ppn.gif\"><img src=\"../img/jdl-faktur-pajak-masukan.gif\" height=\"25\"></td>
		</tr>
		</table>
		<form name=\"form1\" method=\"post\" action=\"?\">
		<table border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"hitam\">
		<tr>
                <td>Buku :&nbsp;</td>
                <td>".combo_array("inp_par[buku]",array("-Pilih-","Sudah","Belum"),$inp_par[buku],"f","onChange=pindah();")."</td>
                <td>&nbsp;Bayar :&nbsp;</td>
                <td>".combo_array("inp_par[bayar]",array("-Pilih-","Sudah","Belum"),$inp_par[bayar],"f","onChange=pindah();")."</td>
                <td>&nbsp;Lapor :&nbsp;</td>
                <td>".combo_array("inp_par[lapor]",array("-Pilih-","Sudah","Belum"),$inp_par[lapor],"f","onChange=pindah();")."</td>
                <td>&nbsp;No Faktur :&nbsp;</td>
                <td><input name=\"inp_par[txtcari]\" type=\"text\" class=\"form1\" size=\"30\" value=\"$inp_par[txtcari]\"></td>
                <td>&nbsp;".combo("select * from tbl_divisi ".divisi("where","divisi_kode")." order by divisi_kode","divisi_kode","divisi_name","inp_par[divisi_kode]","",$inp_par[divisi_kode],"t","onChange=pindah();","","f")."</td>
		<td>&nbsp;Periode :&nbsp;</td>
		<td> ".combo_tanggal("inp_par[hari]",$inp_par[hari],1,31)."".combo_bulan("inp_par[bulan]",$inp_par[bulan])."".combo_tanggal("inp_par[tahun]",$inp_par[tahun],$inp_par[tahun]-7,$inp_par[tahun]+7)." </td>
		<td>&nbsp;S/D :&nbsp;</td>
		<td> ".combo_tanggal("inp_par[hari_]",$inp_par[hari_],1,31)."".combo_bulan("inp_par[bulan_]",$inp_par[bulan_])."".combo_tanggal("inp_par[tahun_]",$inp_par[tahun_],$inp_par[tahun_]-7,$inp_par[tahun_]+7)." </td>
                <td>&nbsp;<input type=submit name=\"go\" value=\"GO &raquo;\" class=\"tombolgo\"></td>
		</tr>
		</table>
		</form>
                
		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"C6E6FF\" class=\"tabel1\">
		<tr class=\"tbltagihan\"> 
		<td width=\"14\"> <div align=\"center\">No</div></td>
		<td width=\"125\"><div align=\"center\">No. Faktur</div></td>
                <td width=\"80\"><div align=\"center\">Tanggal</div></td>
		<td width=\"125\"><div align=\"center\">Proyek</div></td>
		<td><div align=\"center\">Nama Rekanan</div></td>
                <td><div align=\"center\">DPP</div></td>
                <td><div align=\"center\">PPN(10%)</div></td>
		<td width=\"100\"><div align=\"center\">Aksi</div></td>
		</tr>";

	$divisi=($inp_par[divisi_kode]=="-1" or $inp_par[divisi_kode]=="")?"":"and divisi_kode='$inp_par[divisi_kode]'";
	$periode="and tgl_faktur>='".$inp_par[tahun]."-".$inp_par[bulan]."-".$inp_par[hari]."' and tgl_faktur<='".$inp_par[tahun_]."-".$inp_par[bulan_]."-".$inp_par[hari_]."'";
        $kata=strtolower(trim($inp_par[txtcari]));
	if($kata<>""){
		$sql_tambahan .= " and (lower(no_faktur_pajak) like('%".$kata."%'))";
	}
        if ($inp_par[buku]=="Belum"){
            $SQLCombo .= " AND is_buku='N'";
        }else if($inp_par[buku]=="Sudah"){
            $SQLCombo .= " AND is_buku='Y'";
        }else{
            $SQLCombo .= "";
        }

        if ($inp_par[bayar]=="Belum"){
            $SQLCombo .= " AND is_bayar='N'";
        }else if($inp_par[bayar]=="Sudah"){
            $SQLCombo .= " AND is_bayar='Y'";
        }else{
            $SQLCombo .= "";
        }

        if ($inp_par[lapor]=="Belum"){
            $SQLCombo .= " AND is_lapor='N'";
        }else if($inp_par[lapor]=="Sudah"){
            $SQLCombo .= " AND is_lapor='Y'";
        }else{
            $SQLCombo .= "";
        }
	$customer=sqlkearray("select id_leveransir,nama_leveransir from m_leveransir");
	$sql="select * from tbl_spt where no_faktur_pajak!='' $periode ".divisi("and","divisi_kode")." $divisi $SQLCombo $sql_tambahan order by tgl_faktur asc ,no_faktur_pajak asc";
//        echo $sql;
	$arr_tabel=definisi_halaman($sql);
	$result=$arr_tabel["res_sql"];
	$i=1+$inp_par[awalan]*$inp_par[jumlah_per_hal];
	while($r=pg_fetch_array($result)){
		$warna=$warna=="#E3F1FC"?"#F4FAFF":"#E3F1FC";
                if ($r[is_buku]=='N'||$r[is_bayar]=='N'||$r[is_lapor]=='N'){
                    $warna="#FF9999";
                }
		$sql1="select * from m_leveransir where id_leveransir='$r[id_leveransir]'";
		$res1=dbresult($sql1);
		$r1=pg_fetch_array($res1);
                $proyek = cari_nilai("select nama_proyek from m_proyek where id_proyek='$r[id_proyek]'");

		$txtout.="<tr onmouseover=\"this.style.backgroundColor='#FDFFDD';\" style=\"background-color: $warna;\" onmouseout=\"this.style.backgroundColor='$warna';\">
			<td><div align=\"center\">$i</div></td>
			<td><a href=\"javascript:Start('?inp_par[mode]=detail&inp_par[divisi_kode]=$r[divisi_kode]&inp_par[no_faktur_pajak]=$r[no_faktur_pajak]&inp_par[id_leveransir]=$r[id_leveransir]',600,400)\" class=\"tiga\">$r[no_faktur_pajak]</a></td>
                        <td>".date_view($r[tgl_faktur])."</div></td>
			<td>$proyek</td>
                        <td>$r1[nama_leveransir]</td>
                        <td><div align=\"right\">".format_mede($r[dpp])."</div></td>
			<td><div align=\"right\">".format_mede($r[ppn])."</div></td>
			<td width=60><div align=\"center\">";
if ($cdivisi_kode==$r[divisi_kode]){
if($permisi["edit"]=="izin"){
	$txtout.="<a href=\"?inp_par[mode]=edit&inp_par[no_faktur_pajak]=$r[no_faktur_pajak]&inp_par[id_leveransir]=$r[id_leveransir]&inp_par[divisi_kode]=$r[divisi_kode]".var_kirim($inp_par,"no_faktur_pajak,id_leveransir,divisi_kode")."\" title=\"ubah data\" class=\"edit\">Edit</a>";
}
if($permisi["delete"]=="izin"){
	$txtout.=" | <a href=\"?inp_par[mode]=del&inp_par[no_faktur_pajak]=$r[no_faktur_pajak]&inp_par[id_leveransir]=$r[id_leveransir]&inp_par[divisi_kode]=$r[divisi_kode]".var_kirim($inp_par,"no_faktur_pajak,id_leveransir,divisi_kode")."\"  onclick=\"return confirm('Anda Yakin Akan Menghapus Data Ini??')\"  title=\"hapus data\" class=\"delete\">Delete</a>";
}
}
//if($permisi["print"]=="izin"){
//	$txtout.="| <a href=\"javascript:Start('print-faktur-masuk.php?inp_par[mode]=print&inp_par[no_faktur_keluar]=$r[no_faktur_keluaran]".var_kirim($inp_par, "mode, no_faktur_keluar")."',800,700)\" style=\"text-decoration:none\">Print</a>";
//}
	$txtout.=" </div></td></tr>";
	$i++;
	}

	$txtout.="</table>
		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tbltagihan\">
		<tr>
		<td>&nbsp;";

if($permisi["add"]=="izin"){
	$txtout.="<input type=\"button\" name=\"Submit3\" value=\"Tambah Data &raquo;\" class=\"tomboladd\" onclick='javascript:window.location=\"?inp_par[mode]=add".var_kirim($inp_par)."\";'>";
}
	$txtout.="</td>
		<td>$arr_tabel[tabel_halaman]</td>
		</tr>
		</table>";
	return $txtout;
}

function detail(){
	global $inp_par,$inp,$permisi,$cdivisi_kode;
        $inp_par[divisi_kode]= $inp_par[divisi_kode] == ""? $cdivisi_kode:$inp_par[divisi_kode];
        $divisi=($inp_par[divisi_kode]=="-1" or $inp_par[divisi_kode]=="")?"":"and divisi_kode='$inp_par[divisi_kode]'";

	$sql="select * from tbl_spt where no_faktur_pajak!='' and id_leveransir='$inp_par[id_leveransir]' and no_faktur_pajak='$inp_par[no_faktur_pajak]' ".divisi("and","divisi_kode")." $divisi order by tgl_faktur asc ,no_faktur_pajak asc";
        $query = dbresult($sql);
        $r=pg_fetch_array($query);
        $buku = $r[is_buku]=="Y"?"SUDAH":"BELUM";
        $bayar = $r[is_bayar]=="Y"?"SUDAH":"BELUM";
        $lapor = $r[is_lapor]=="Y"?"SUDAH":"BELUM";
        $laporS = explode("-",$r[tanggal_lapor]);
        $tanggal_lapor = $laporS[1]."/".$laporS[0];
        $tanggal_lapor=$lapor=="SUDAH"?$tanggal_lapor:"";

        $proyek = cari_nilai("select nama_proyek from m_proyek where id_proyek='$r[id_proyek]'");
        $sql1="select * from m_leveransir where id_leveransir='$r[id_leveransir]'";
	$res1=dbresult($sql1);
	$r1=pg_fetch_array($res1);


	$txtout.="<table width=\"98%\" height=\"35\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
		<td height=\"5\" colspan=\"2\"><img src=\"../img/0.gif\" width=\"1\" height=\"10\"></td>
		</tr>
		<tr>
		<td width=\"15\" background=\"../img/bg-judul-tagihan.gif\">&nbsp;</td>
		<td height=\"25\" background=\"../img/bg-judul-tagihan.gif\"><img src=\"../img/jdl-faktur-masuk.gif\" width=\"148\" height=\"25\"></td>
		</tr>
		</table>

		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"C6E6FF\" class=\"tabel1\">
                <tr class=\"tbltagihan\"><td colspan=5>&nbsp;DETAIL FAKTUR PAJAK</td>;
                </tr>
                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">1.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">NO FAKTUR</td>
                <td width=\"5\" bgcolor=\"#FFFFFF\" valign=\"top\">:</td>
		<td colspan=2>&nbsp;$r[no_faktur_pajak]</td>
		</tr>
                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">2.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">TGL FAKTUR</td>
                <td width=\"5\" bgcolor=\"#FFFFFF\" valign=\"top\">:</td>
		<td colspan=2>&nbsp;".date_view($r[tgl_faktur])."</td>
		</tr>
                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">3.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">PROYEK</td>
                <td width=\"5\" bgcolor=\"#FFFFFF\" valign=\"top\">:</td>
		<td colspan=2>&nbsp;$proyek</td>
		</tr>
                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">4.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">NAMA REKANAN</td>
                <td width=\"5\" bgcolor=\"#FFFFFF\" valign=\"top\">:</td>
		<td colspan=2>&nbsp;$r1[nama_leveransir]</td>
		</tr>
                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">5.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">NPWP REKANAN</td>
                <td width=\"5\" bgcolor=\"#FFFFFF\" valign=\"top\">:</td>
		<td colspan=2>&nbsp;$r1[npwp_leveransir]</td>
		</tr>
                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">6.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">ALAMAT REKANAN</td>
                <td width=\"5\" bgcolor=\"#FFFFFF\" valign=\"top\">:</td>
		<td colspan=2>&nbsp;$r1[alamat_leveransir]</td>
		</tr>
                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">7.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">DPP</td>
                <td width=\"5\" bgcolor=\"#FFFFFF\" valign=\"top\">:</td>
		<td colspan=2>&nbsp;".number_format($r[dpp])."</td>
		</tr>
                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">8.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">PPN (10%)</td>
                <td width=\"5\" bgcolor=\"#FFFFFF\" valign=\"top\">:</td>
		<td colspan=2>&nbsp;".number_format($r[ppn])."</td>
		</tr>
                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">9.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">PEMBUKUAN</td>
                <td width=\"5\" bgcolor=\"#FFFFFF\" valign=\"top\">:</td>
		<td width=\"130\">&nbsp;$buku</td>
                <td>&nbsp;$r[bukti_pembukuan]</td>
		</tr>
                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">10.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">PEMBAYARAN</td>
                <td width=\"5\" bgcolor=\"#FFFFFF\" valign=\"top\">:</td>
		<td width=\"130\">&nbsp;$bayar</td>
                <td>&nbsp;$r[bukti_pembayaran]</td>
		</tr>
                <tr bgcolor=\"#FFFFFF\" valign=\"top\">
		<td width=\"30\" valign=\"top\"><div align=\"center\">11.</div></td>
		<td width=\"130\" bgcolor=\"#FFFFFF\" valign=\"top\">LAPOR SPT MASA</td>
                <td width=\"5\" bgcolor=\"#FFFFFF\" valign=\"top\">:</td>
		<td width=\"130\">&nbsp;$lapor</td>
                <td>&nbsp;$tanggal_lapor</td>
		</tr>
		";
	$txtout.="</table>
		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tbltagihan\">
		<tr>
		<td>&nbsp;";
	$txtout.="</td>
		<td align=center><input type=\"button\" name=\"exit\" value=\"Exit\" class=\"tomboladd\" onClick=\"top.window.close();\"></td>
		</tr>
		</table>";
	return $txtout;
}


function generate_form($inp_par){
	global $inp;
	switch ($inp_par[mode]) {

		case "add":
			$txtout.=$inp[aksi]==""?form():tambah();
		break;
		case "edit":
			$txtout.=$inp[aksi]==""?form():ubah();
		break;
		case "del":
			$txtout.=hapus();
		break;
		case "detail_":
			$txtout.=detail_dua();
		break;

		case "detail":
			$txtout.=detail();
		break;
		default:
		$txtout.=lihat();
		break;
	}
	return $txtout;
}

?>

